clear
rng default
load IdSetM_final_1
IdSetM{1}=IdSetM_final_1;
load IdSetM_final_2
IdSetM{2}=IdSetM_final_2;
load IdSetM_final_3
IdSetM{3}=IdSetM_final_3; 
load IdSetM_final_4
IdSetM{4}=IdSetM_final_4;
load IdSetW_final_1
IdSetW{1}=IdSetW_final_1;
load IdSetW_final_2
IdSetW{2}=IdSetW_final_2;
load IdSetW_final_3
IdSetW{3}=IdSetW_final_3; 
load IdSetW_final_4
IdSetW{4}=IdSetW_final_4;

ntypes_m=4;
ntypes_w=4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Projections in one dimension %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Phi=cell(ntypes_m, ntypes_w);
for i=2:ntypes_m+1
    for j=2:ntypes_w+1
        M=unique(IdSetM{i-1}(:,j), 'rows', 'stable'); 
        W=unique(IdSetW{j-1}(:,i), 'rows', 'stable');
        sm=size(M,1);
        temp=cell(sm,1);
        for k=1:sm
            temp{k}=M(k)+W(:); 
        end
        temp=vertcat(temp{:});
        Phi{i-1,j-1}=[min(temp); max(temp)];
    end
end

save('Phi_intervals.mat', 'Phi')

load U_CS
load V_CS

Phi_CS=U_CS+V_CS;
save('Phi_CS.mat', 'Phi_CS')



